﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Projectmanagement.Utl;
using Telerik.Web.Mvc;
using Projectmanagement.Entity;
using ProjectManagement.Models;

namespace Projectmanagement.Controllers
{
    public class AllTaskController : Controller
    {
        //
        // GET: /AllTask/

        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult _SelectAllTaskIndex(string taskCode, string name, DateTime? start, DateTime? end, int? state, int? projectid, string member)
        {
            if (member == "-请选择-")
            {
                member = "";
            }
            var task = DQ.GetTasksSearch(projectid, member, 0, state ?? 0, "", true, taskCode);

            if (start != null)
            {
                task = task.Where(s => s.StartDate >= start);
            }
            if (end != null)
            {
                task = task.Where(s => s.EndDate <= end);
            }
            if (!string.IsNullOrWhiteSpace(name))
            {
                task = task.Where(s => s.Name.Contains(name));
            }
            if (state != null)
            {
                task = task.Where(s => s.TaskStateID == state);
            }

            return View(new GridModel(task));
        }

    }
}
